<template>
	<view>
		<view class="swiper square">
			<swiper class="skeleton-rect" indicator-dots="true"
				:autoplay="true" :circular="circular" :interval="interval" :duration="duration"
				indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff" :current="swiperCur"
				@change="swiperChange" style="height: 400rpx;">
				<block v-for="(item,index) in carousels" :key="index">
					<swiper-item class="" :class="{active:index == swiperCur}">
						<view style="height: 400rpx;" @click="goDetail(item)" class='slide-navigator acea-row row-between-wrapper'>
							<image :src="item.cover" class="slide-image"></image>
						</view>
					</swiper-item>
				</block>
		
			</swiper>
		</view><!-- 轮播图 end -->
		
		<view class="loc_item_bg">
			
			<view class="section">
				<view class="title">
					<image src="../../static/images/weizhi.png" class="cover"></image>
					维修项目
				</view>
				<view class="text" @click="select(1)" v-if="sele_names.length == 0">请选择</view>
				<view class="text" @click="select(1)" v-else>{{sele_names}}</view>
			</view><!-- section end -->
			<view class="line"></view>
			<view class="section">
				<view class="title">
					<image src="../../static/images/weizhi.png" class="cover"></image>
					所在位置
				</view>
				<view class="text" @click="select(2)" v-if="address == ''">请选择</view>
				<view class="text" @click="select(2)" v-else>{{address}}</view>
				<image class="current" @click="select(2)" src="../../static/images/current_loc.png"></image>
			</view><!-- section end -->
		</view><!-- loc_item_bg -->
		<view class="func">
			<view class="btn" @click="queryPrice">立即查价</view>
		</view><!-- func end -->
		
		<view class="blocks">
			<view class="block">
				<view class="top">
					<view class="top_title">推荐门店</view>
					<!-- <view class="top_more" @click="gotoMore()">
						<view class="more_text">其他路线</view>
						<image class="more_arrow" src="../../../static/images/arrow.png"></image>
					</view> -->
				</view>
				<!-- <view class="empty" v-if="doing_data.length == 0">
					<view class="empty_bg">
						<image class="empty_class" src="/static/images/empty_img.png"></image>
					</view>
					<view class="desc_bg">
						周围有
						<text class="red" v-if="driver>10000">{{driver/10000}}w+</text>
						<text class="red" v-else>{{driver}}</text>
						司机等您发货
					</view>
				</view> -->
				<view class="items">
					<view class="item" @click="gotoDetail(item)" v-for="item in data">
						<image :src="item.cover" class="cover"></image>
						<view class="center">
							<view class="name">{{item.name}}</view>
							<view class="address">{{item.address}}3号</view>
							<view class="phone">{{item.contact}}</view>
						</view>
						<view class="right">
							
						</view>
					</view>
				</view>
			</view><!--block end-->
		</view><!--blocks end-->
	</view>
</template>

<script>
	import {index} from "@/api/index.js";
	import {store_rec_list} from "@/api/platform.js";
	export default {
		data() {
			return {
				showSkeleton: true, //骨架屏显示隐藏
				indicatorDots: false,
				circular: true,
				autoplay: true,
				interval: 4000,
				duration: 500,
				carousels:[],//轮播
				data:[],//推荐门店
				address:'',//地址
				items:'',//选择的项目
				sele_names:'',
				lon:0,
				lat:0,
			}
		},
		onShareTimeline() {
			return {
				title: '汽修精灵',
				//分享朋友圈的参数
				query: "isShare=1&id=",
			}
		},
		onShareAppMessage(){
		},
		onLoad() {
			this.getIndex();
			this.getData();
		},
		created() {
			
		},
		methods: {
			swiperChange(e){
				
			},
			select(type){
				if(type == 1){
					uni.navigateTo({
						url:'/pages/info/index'
					})
				}else{
					console.info(1111)
					let that = this;
					uni.authorize({
						scope:"scope.userLocation",
						success(res) {
							uni.chooseLocation({
								success(res) {
									console.info(res)
									that.address = res.address;
									that.lon = res.longitude;
									that.lat = res.latitude;
								}
							})
						},
						fail(err) {
							
						}
					})
				}
			},
			//轮播
			getIndex(){
				let that = this;
				index({}).then((res) => {
					let data = res.data;
					that.carousels = data.banners;
					that.ads = data.ads;
					that.driver = data.driver;
					if(data.driver < 100){
						that.driver = Math.floor(Math.random() * (100 - 50 + 1) ) + 50;
					}
				});
			},
			//推荐门店
			getData(){
				let that = this;
				store_rec_list({}).then((res) => {
					let data = res.data.list;
					that.data = data;
				});
			},
			//立即查价 
			queryPrice(){
				if(this.items.length == 0){
					uni.showToast({
						icon:'none',
						title:'请选择项目'
					})
					return;
				}
				if(this.address.length == 0){
					uni.showToast({
						icon:'none',
						title:'请选择地址'
					})
					return;
				}
				uni.navigateTo({
					url:'/pages/query/index?ids='+this.items + '&address='+this.address+"&lon="+this.lon+"&lat="+this.lat
				})
			},
			//进入门店明细
			gotoDetail(item){
				uni.navigateTo({
					url:'/pages/store/index?id='+item.id
				})
			},
			//选择项目回调
			selectItems(data,sele_names){
				this.sele_names = sele_names;
				this.items = data;
			}
		}

	}
</script>

<style lang="scss" scope>
	view{
		background-color: white;
	}
	page{
		background-color: white;
	}
	.swiper{
		// mheight: 500rpx;
		padding: 0 0;
		.slide-image{
			width: 100%;
			height: 400rpx;
		}
	}
	
	.loc_item_bg{
		background-color: white;
		margin-top: 20rpx;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		.line{
			height: 1rpx;
			width: 100%;
			border-bottom: 1rpx solid #f1f1f1;
		}
		.section{
			height: 80rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			.title{
				font-size: 28rpx;
				color: black;
				display: flex;
				flex-direction: row;
				align-items: center;
				width: 150rpx;
				.cover{
					width: 24rpx;
					height:24rpx;
					margin-right: 10rpx;
				}
			}
			.text{
				flex: 1;
				font-size: 28rpx;
				color: darkgray;
				margin-left: 30rpx;
			}
			
			.current{
				width: 50rpx;
				height: 50rpx;
				margin-right: 15rpx;
				margin-left: 20rpx;
			}
		}
	}
	
	.func{
		background-color: white;
		// padding: 30rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		margin-top: 30rpx;
		.btn{
			font-size: 28rpx;
			color: white;
			margin-top: 10rpx;
			background-color: #dd783f;
			width: 100%;
			height: 80rpx;
			text-align: center;
			line-height: 80rpx;
		}
	}
	
	.blocks{
		display: flex;
		flex-direction: column;
		padding: 30rpx;
	
		.block{
			display: flex;
			flex-direction: column;
			margin-top: 10rpx;
			padding: 0rpx 0rpx;
				
			.top{
				height: 80rpx;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				.top_title{
					font-weight: bold;
					color: black;
					font-size: 28rpx;
				}
				.top_more{
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					.more_text{
						color: gray;
						font-size: 28rpx;
					}
					.more_arrow{
						width: 26rpx;
						height:26rpx;
					}
				}
			}
			.empty{
				display: flex;
				flex-direction: column;
				justify-content:center;
				.empty_bg{
					display: flex;
					flex-direction: row;
					justify-content:center;
					margin-top: 100rpx;
					.empty_class{
						width:224rpx;
						height:146rpx;
					}
				}
				.desc_bg{
					text-align: center;
					font-size: 28rpx;
					color: black;
					margin-top: 40rpx;
					margin-bottom: 100rpx;
					.red{
						font-size: 42rpx;
						color: darkorange;
					}
				}
			}
			.items{
				display: flex;
				flex-direction: column;
				background-color: white;
				.item{
					display: flex;
					flex-direction: row; 
					justify-content: space-between;
					margin-bottom: 30rpx;
					padding-bottom: 30rpx;
					border-bottom: 1rpx solid #f1f1f1;
					
					.cover{
						width: 200rpx;
						height: 160rpx;
						border-radius: 10rpx;
					}
					.center{
						flex: 1;
						display: flex;
						flex-direction: column;
						margin-left: 15rpx;
						.name{
							font-size: 28rpx;
							font-weight: bold;
							color: black;
						}
						.address{
							font-size: 26rpx;
							color: gray;
							margin-top: 15rpx;
						}
						.phone{
							font-size: 26rpx;
							color: gray;
							margin-top: 15rpx;
						}
					}
					.right{
						margin-left: 15rpx;
						width: 80rpx;
						color: gray;
						font-size: 28rpx;
						display: flex;
						flex-direction: row;
						align-items: center;
					}
				}
			}
		}
		
		
	}
	/** 须知弹窗 **/
	.popup-cls{
		display: flex;
		flex-direction: column;
		.pop-info{
			width:100%;
			display: flex;
			flex-direction: column;
			border-radius: 20rpx;
			margin: 0 auto;
			background-color: white;
			.pop-top{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				font-weight: bold;
				margin-top: 20rpx;
				text-align: center;
				padding-bottom: 30rpx;
				.cancel{
					font-size: 28rpx;
					color: dimgray;
					margin-left:30rpx;
					height: 60rpx;
					width: 130rpx;
					line-height: 60rpx;
				}
				.title{
					font-size: 30rpx;
					font-weight: bold;
				}
				.confirm{
					background-color: $uni-main-color;
					color: white;
					font-size: 28rpx;
					height: 60rpx;
					width: 130rpx;
					border-radius: 30rpx;
					line-height: 60rpx;
					margin-right:30rpx;
				}
			}
		}
		
		.center{
			width:100%;
			display: flex;
			flex-direction: column;
			.top_bg{
				background-color: oldlace;
				height: 80rpx;
				color: darkorange;
				font-size: 30rpx;
				line-height: 80rpx;
				padding-left: 30rpx;
			}
			.pop-content{
				padding: 0rpx 30rpx;
				display: flex;
				flex-direction: row;
				height: 500rpx;
				margin-top: 30rpx;
				.left{
					width: 280rpx;
					background-color: #f8f8f8;
					.section{
						padding-left: 30rpx;
						height: 80rpx;
						color: black;
						font-size: 28rpx;
						background-color: transparent;
						line-height: 80rpx;
					}
					.selected{
						background-color: white;
						color: darkorange;
						font-weight: bold;
					}
				}
				.right{
					margin-left: 30rpx;
					flex: 1;
					background-color: white;
					.section{
						height: 80rpx;
						color: black;
						font-size: 28rpx;
						line-height: 80rpx;
					}
					.selected{
						background-color: white;
						color: darkorange;
						font-weight: bold;
					}
				}
			}
		}
		
	}//popup-cls end
</style>
